﻿using System;
using System.Xml;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace WorldBuilder
{
    class XMLReader
    {
        XmlTextReader textReader;
        
        LevelData newLevelData;
        
        public XMLReader(string sFile)
        {
            textReader = new XmlTextReader(sFile);  // File Location to open. 
            
         
            newLevelData = new LevelData(0, 0, 0, 0, 0);
            
        }

        public void ReadLevelData_2D()
        {
            textReader.Read();

            //if the node has a value
            while (textReader.Read())
            {
                //Move to first Element
                textReader.MoveToElement();
                if (textReader.Name == "Description")
                {
                    textReader.Read(); // We have to move ahead one or else we get a blank value.
                   
                    newLevelData.SetDescription(textReader.Value);
                    textReader.Read(); // If we dont call it again we will get same Name but no value
                    
                   
                }
                if (textReader.Name == "MapSizeWidth")
                {
                    textReader.Read(); // We have to move ahead one or else we get a blank value.
                   
                    newLevelData.SetMapSizeX(textReader.Value);
                   
                    textReader.Read(); // If we dont call it again we will get same Name but no value

                }
                if (textReader.Name == "MapSizeHeight")
                {
                    textReader.Read(); // We have to move ahead one or else we get a blank value.
                    
                    newLevelData.SetMapSizeY(textReader.Value);
                    textReader.Read(); // If we dont call it again we will get same Name but no value

                }
                if (textReader.Name == "MapData")
                {
                    textReader.Read(); // We have to move ahead one or else we get a blank value.
                    
                    newLevelData.SetMap(textReader.Value);
                    textReader.Read(); // If we dont call it again we will get same Name but no value
                    

                }
                
            }
        }

        public void ReadLevelData_3D()
        {
            textReader.Read();
 
            //if the node has a value
            while (textReader.Read())
            {
                //Move to first Element
                textReader.MoveToElement();
                if (textReader.Name == "Description")
                {
                    textReader.Read(); // We have to move ahead one or else we get a blank value.
                    newLevelData.SetDescription(textReader.Value);

                }
                if (textReader.Name == "MapSizeWidth")
                {
                    textReader.Read(); // We have to move ahead one or else we get a blank value.
                     //Set the MapSize

                }
                if (textReader.Name == "MapSizeHeight")
                {
                    textReader.Read(); // We have to move ahead one or else we get a blank value.
                    //Set the MapSize

                }
                if (textReader.Name == "Vertices")
                {
                    textReader.Read(); // We have to move ahead one or else we get a blank value.
                    //import this data into the vertices

                }

            }
        }
    }
}
